import { RegisterComponent } from "@feng3d/ecs";
import { DirectionalLight } from "../../thirdparty/three/imports";
import { DirectionalLightShadow3D } from "./DirectionalLightShadow3D";
import { Light3D } from "./Light3D";

declare module "@feng3d/ecs"
{
    interface ComponentMap { DirectionalLight3D: DirectionalLight3D; }
}

/**
 * 3D点光源，包装`three`中`PointLight`
 */
@RegisterComponent({ name: 'DirectionalLight3D' })
export class DirectionalLight3D extends Light3D
{
    _light: DirectionalLight = new DirectionalLight();

    shadow: DirectionalLightShadow3D = new DirectionalLightShadow3D(this._light.shadow);

    init()
    {
        // 重置方向光源坐标 @see https://github.com/mrdoob/three.js/blob/r149/src/lights/DirectionalLight.js#L15
        this._entity._group.position.copy(this._light.position);
        this._light.position.set(0, 0, 0);
        super.init();
    }

    destroy(): void
    {
        this.shadow = null;

        super.destroy();
    }
}
